<template>
  <div class="page-header">
    <div class="left">
      <van-icon v-if="showBack" name="arrow-left" class="back-icon" @click="handleBack" />
    </div>
    <div class="title">{{ title }}</div>
    <div class="right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  showBack: {
    type: Boolean,
    default: true,
  },
  customBack: {
    type: Function,
    default: null,
  },
})

const router = useRouter()

const handleBack = () => {
  if (props.customBack) {
    props.customBack()
  } else {
    router.back()
  }
}
</script>

<style scoped lang="scss">
.page-header {
  display: flex;
  align-items: center;
  height: 44px;
  background-color: $white;
  position: relative;
  padding: 0 $padding-md;
  border-bottom: 1px solid #f5f5f5;

  .left {
    width: 24px;
    flex-shrink: 0;

    .back-icon {
      font-size: 18px;
      color: $text-color;
    }
  }

  .title {
    flex: 1;
    text-align: center;
    font-size: $font-size-lg;
    font-weight: 500;
    color: $text-color;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 $padding-md;
  }

  .right {
    width: 24px;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
  }
}
</style> 